package ${bag}.service.impl;

import ${bag}.domain.${name};
import ${bag}.repository.${name}Repository;
import ${bag}.service.I${name}Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class ${name}ServiceImpl implements I${name}Service {
    @Autowired
    private ${name}Repository ${lname}Repository;

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void save(${name} ${lname}) {
    ${lname}Repository.save(${lname});
    }

    @Override
    public void update(${name} ${lname}) {
    ${lname}Repository.save(${lname});
    }

    @Override
    public void delete(String id) {
    ${lname}Repository.deleteById(id);
    }

    @Override
    public ${name} get(String id) {
        return ${lname}Repository.findById(id).orElse(null);
    }

    @Override
    public List<${name}> listAll() {
    return ${lname}Repository.findAll();
    }

    @Override
    public void saveOrUpdate(${name} ${lname}) {
        // 冗余字段数据维护
        if (StringUtils.hasLength(${lname}.getId())){
            this.update(${lname});
        }else {
            this.save(${lname});
        }
    }
}